package com.example.springboot.controller;

import com.example.springboot.entity.Base;
import com.example.springboot.entity.User;
import com.example.springboot.mapper.BaseMapper;
import com.example.springboot.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/base")
public class BaseController {
@Autowired
    private BaseMapper baseMapper;
@Autowired
private BaseService baseService;
@GetMapping
public Map<String, Object> index1(@RequestParam Integer pageNum, @RequestParam Integer pageSize, @RequestParam String name){
    pageNum=(pageNum-1)*pageSize;
    List<Base> data=baseMapper.selectPage(pageNum,pageSize,name);
    Integer total = baseMapper.selectTotal(name);
    Map<String,Object> res=new HashMap<>();
    res.put("code",200);
    res.put("data",data);
    res.put("total",total);

    return res;

//        return userMapper.findAll();
}
    @PostMapping("/add")
    public Map<String,Object> save(@RequestBody Base base){
        Map<String,Object> res=new HashMap<>();
        if(baseService.save(base) == 1){
            res.put("code",200);
            res.put("msg","成功");
        }
        return res;
        //    return userService.save(user);
    }
    @PostMapping("/add1")
    public Map<String,Object> save1(@RequestBody Base base){
        Map<String,Object> res=new HashMap<>();
        if(baseService.save1(base) == 1){
            res.put("code",200);
            res.put("msg","成功");
        }
        return res;
        //    return userService.save(user);
    }
    @PostMapping("/glwc")
    public Map<String,Object> update(@RequestBody Base base){
    Map<String,Object> res=new HashMap<>();
    if(baseService.update(base) == 1){
        res.put("code",200);
        res.put("msg","修改成功");
    }
        return res;
    }

@GetMapping("/qzhz")
public Map<String, Object> qzhz(@RequestParam Integer pageNum, @RequestParam Integer pageSize, @RequestParam String name){
    pageNum=(pageNum-1)*pageSize;
    List<Base> data=baseMapper.selectqzpg(pageNum,pageSize,name);
    Integer total = baseMapper.selectqzTotal(name);
    Map<String,Object> res=new HashMap<>();
    res.put("code",200);
    res.put("data",data);
    res.put("total",total);

    return res;

//        return userMapper.findAll();
}
@GetMapping("/cxhsxx")
public Map<String,Object> cxhsxx(@RequestParam String baseId){
    List<Base> data=baseMapper.cxhs(baseId);
    Map<String,Object> res=new HashMap<>();
    res.put("data",data);
    return res;
}
    @PostMapping("/xgzlxx")
    public Map<String,Object> updatezl(@RequestBody Base base){
        Map<String,Object> res=new HashMap<>();
        if(baseService.updatezl(base) == 1){
            res.put("code",200);
            res.put("msg","修改成功");
        }
        return res;
    }

    @PostMapping("/savehs")
    public Map<String,Object> savehs(@RequestBody Base base){
        Map<String,Object> res=new HashMap<>();
        if(baseService.savehs(base) == 1){
            res.put("code",200);
            res.put("msg","成功");
        }
        return res;
        //    return userService.save(user);
    }
    @PostMapping("/savezy")
    public Map<String,Object> savezy(@RequestBody Base base){
        Map<String,Object> res=new HashMap<>();
        if(baseService.savezy(base) == 1){
            res.put("code",200);
            res.put("msg","成功");
        }
        return res;
        //    return userService.save(user);
    }
    @PostMapping("/savesw")
    public Map<String,Object> savesw(@RequestBody Base base){
        Map<String,Object> res=new HashMap<>();
        if(baseService.savesw(base) == 1){
            res.put("code",200);
            res.put("msg","成功");
        }
        return res;
        //    return userService.save(user);
    }
    @GetMapping("/swlist")
    public Map<String, Object> swhz(@RequestParam Integer pageNum, @RequestParam Integer pageSize, @RequestParam String name){
        pageNum=(pageNum-1)*pageSize;
        List<Base> data=baseMapper.cxsw(pageNum,pageSize,name);
        Integer total = baseMapper.cxswTotal(name);
        Map<String,Object> res=new HashMap<>();
        res.put("code",200);
        res.put("data",data);
        res.put("total",total);
        return res;
    }
    @GetMapping("/zylist")
    public Map<String, Object> zyhz(@RequestParam Integer pageNum, @RequestParam Integer pageSize, @RequestParam String name){
        pageNum=(pageNum-1)*pageSize;
        List<Base> data=baseMapper.cxzy(pageNum,pageSize,name);
        Integer total = baseMapper.cxzyTotal(name);
        Map<String,Object> res=new HashMap<>();
        res.put("code",200);
        res.put("data",data);
        res.put("total",total);
        return res;
    }
    @GetMapping("/indextotal")
    public Map<String, Object> indexzs(@RequestParam String name){

        Integer total = baseMapper.selectqzTotal(name);
        Integer total1 = baseMapper.cxswTotal(name);
        Integer total2 = baseMapper.cxzyTotal(name);
        Integer total3 = baseMapper.selectTotal(name);

        Map<String,Object> res=new HashMap<>();
        res.put("code",200);
        res.put("qz",total);
        res.put("sw",total1);
        res.put("zy",total2);
        res.put("mj",total3);
        return res;
    }
}
